package cluster

import (
	"strconv"
	"strings"
)

// ServerJobType 服务器职责类型, 简写为 sjt
type ServerJobType uint16

const (
	E_Sjt_Login ServerJobType = iota + 1 // 1
	E_Sjt_Game                           // 2
)

// 转为字符串
func (sjt ServerJobType) ToStr() string {
	switch sjt {
	case E_Sjt_Login:
		return "LOGIN"
	case E_Sjt_Game:
		return "GAME"
	default:
		return ""
	}
}

// 字符串转为服务器职责类型
func StrToSjt(val string) ServerJobType {
	if strings.EqualFold(val, "LOGIN") || // 和 "LOGIN" 比较
		strings.EqualFold(val, strconv.Itoa(int(E_Sjt_Login))) { // 和 "1" 比较
		return E_Sjt_Login
	}

	if strings.EqualFold(val, "GAME") || // 和 "GAME" 比较
		strings.EqualFold(val, strconv.Itoa(int(E_Sjt_Game))) { // 和 "2" 比较
		return E_Sjt_Game
	}

	panic("无法转型为服务器职责类型")
}

// 字符串转为服务器职责类型数组
func StrToSjtArray(val string) []ServerJobType {
	if len(val) <= 0 {
		return nil
	}

	strArray := strings.Split(val, ",")
	var enumArray []ServerJobType

	for _, currStr := range strArray {
		sjt := StrToSjt(currStr)
		enumArray = append(enumArray, sjt)
	}

	return enumArray
}
